ALMaSS  1.0
The Animal, Landscape and Man Simulation System
skylarks_all.h
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2011, Christopher John Topping, University of Aarhus
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
24 
25 //---------------------------------------------------------------------------
26 #ifndef Skylarks_All_H
27  #define Skylarks_All_H
28 //---------------------------------------------------------------------------
29 
30 #define UNREFERENCED_PARAMETER(P) (P)
31 
32 using namespace std;
33 
34 typedef enum
35 {
42 
43 typedef enum
44 {
46  //Clutch
48  //Nestling
50  //PreFledgeling
52  //MaleSK
56  //FemaleSK
61  // Destroy object state
64 
65 // Forward declarations
66 class Skylark_Base;
67 class Skylark_Clutch;
68 class Skylark_Nestling;
70 class Skylark_Female;
71 class Skylark_Male;
72 class Landscape;
73 class SkTerritories;
74 class TForm1;
75 class Population_Manager;
76 class probe_data;
77 
78 //------------------------------------------------------------------------------
79 // Class Declarations
80 //------------------------------------------------------------------------------
81 
82 
83 
84 template < class T >
85 class TSkylarkList : public vector < T >
86 {
87 public:
88  TSkylarkList() : vector < T > ()
89  {
90  }
91 
92  //------------------------------------------------------------------------------
93  double Probe( probe_data * p_TheProbe )
94  {
95 
96  // Counts through the list and goes through each area to see if the animal
97  // is standing there and if the farm, veg or element conditions are met
98  AnimalPosition Sp;
99  double NumberSk = 0;
100  // Four possibilites
101  // either NoVegTypes or NoElementTypes or NoFarmTypes is >0 or all==0
102  if ( p_TheProbe->m_NoFarms != 0 )
103  {
104  for ( unsigned j = 0; j < this->GetItemsInContainer(); j++ )
105  {
106  Sp = this->Get( j )->SupplyPosition();
107  unsigned Farm = this->Get( j )->SupplyFarmOwnerRef();
108  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ )
109  {
110  if ( ( Sp.m_x >= p_TheProbe->m_Rect[i].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[i].m_y1 )
111  && ( Sp.m_x < p_TheProbe->m_Rect[i].m_x2 ) && ( Sp.m_y < p_TheProbe->m_Rect[i].m_y2 ) )
112  for ( unsigned k = 0; k < p_TheProbe->m_NoFarms; k++ )
113  {
114  if ( p_TheProbe->m_RefFarms[k] == Farm )
115  NumberSk++; // it is in the square so increment number
116  }
117  }
118  }
119  }
120  if ( p_TheProbe->m_NoEleTypes != 0 )
121  {
122  for ( unsigned j = 0; j < this->GetItemsInContainer(); j++ )
123  {
124  Sp = this->Get( j )->SupplyPosition();
125  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ )
126  {
127  if ( ( Sp.m_x >= p_TheProbe->m_Rect[i].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[i].m_y1 )
128  && ( Sp.m_x < p_TheProbe->m_Rect[i].m_x2 ) && ( Sp.m_y < p_TheProbe->m_Rect[i].m_y2 ) )
129  for ( unsigned k = 0; k < p_TheProbe->m_NoEleTypes; k++ )
130  {
131  if ( p_TheProbe->m_RefEle[k] == Sp.m_EleType )
132  NumberSk++; // it is in the square so increment number
133  }
134  }
135  }
136  }
137  else
138  {
139  if ( p_TheProbe->m_NoVegTypes != 0 )
140  {
141  for ( unsigned j = 0; j < this->GetItemsInContainer(); j++ )
142  {
143  Sp = this->Get( j )->SupplyPosition();
144  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ )
145  {
146  if ( ( Sp.m_x >= p_TheProbe->m_Rect[i].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[i].m_y1 )
147  && ( Sp.m_x < p_TheProbe->m_Rect[i].m_x2 ) && ( Sp.m_y < p_TheProbe->m_Rect[i].m_y2 ) )
148  {
149  for ( unsigned k = 0; k < p_TheProbe->m_NoVegTypes; k++ )
150  {
151  if ( p_TheProbe->m_RefVeg[k] == Sp.m_VegType )
152  NumberSk++; // it is in the square so increment number
153  }
154  }
155  }
156  }
157  }
158  else // both must be zero
159  {
160  for ( unsigned j = 0; j < this->GetItemsInContainer(); j++ )
161  {
162  Sp = this->Get( j )->SupplyPosition();
163  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ )
164  {
165  if ( ( Sp.m_x >= p_TheProbe->m_Rect[i].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[i].m_y1 )
166  && ( Sp.m_x < p_TheProbe->m_Rect[i].m_x2 ) && ( Sp.m_y < p_TheProbe->m_Rect[i].m_y2 ) )
167  NumberSk++; // it is in the square so increment number
168  }
169  }
170  }
171  }
172  return NumberSk;
173  }
174  //------------------------------------------------------------------------------
175 
176 
177 };
178 
179 
180 
181 //----------------------------------------------------------------------------
182 
184 {
185 public:
186  int x;
187  int y;
188  bool found;
189 };
190 
191 
192 
193 //----------------------------------------------------------------------------
194 
196 {
197 public:
198  int x;
199  int y;
200  int bx;
201  int by;
202  int mh;
205 
206  virtual ~Skylark_struct()
207  {
208  }
209 };
210 
211 
212 
213 //------------------------------------------------------------------------------
214 
215 
217 {
218 public:
219  int No;
221 };
222 
223 
224 
225 //------------------------------------------------------------------------------
226 
228 {
229 public:
231 };
232 
233 
234 
235 //------------------------------------------------------------------------------
236 
238 {
239 public:
240  double size;
242  bool sex;
243  int age;
244 };
245 
246 
247 
248 //------------------------------------------------------------------------------
249 
251 {
252 public:
253  double size;
254  bool sex;
255  int age;
256 };
257 
258 
259 
260 //------------------------------------------------------------------------------
261 
263 {
264 public:
265  vector < int > m_polys;
266  vector < int > m_sizes;
267  vector < int > m_hr_polys;
268  vector < int > m_hr_sizes;
269 
277  double GetVirtualDiameter() { return m_VirtualDiameter; }
278  void SetVirtualDiameter(double dia) { m_VirtualDiameter = dia; }
279 
280 
281  int Size; // it is square so we need only one dimension
284  int GetQuality(void) { return m_Quality; }
285  void SetQuality(int a_qual) { m_Quality = a_qual; }
288  skTTerritory( int x, int y, int TheSize, int TheQuality, int a_x_div10, int a_y_div10, int a_range_div10 );
289  // assume we store the quality here - question of efficiency
290  void TestNestPossibility();
291  void SetNestPossibility(bool valid, int nx, int ny) {
292  m_nest_valid=valid;
293  m_nest_pos_validx=nx;
294  m_nest_pos_validy=ny;
295  }
296 protected:
300 };
301 
302 
303 
304 //------------------------------------------------------------------------------
306 {
307 public:
308  int x;
309  int y;
310  int size;
311  int ref;
312  double nqual;
313  bool validnest;
314 };
315 
316 
317 
318 //------------------------------------------------------------------------------
319 
320 
322 {
323 public:
324  vector < int > m_sizes;
325  vector < int > m_polys;
326  double m_qual;
327 
328  int Insert( int a_poly )
329  {
330  int l_size = (int) m_sizes.size();
331  m_sizes.resize( l_size + 1 );
332  m_polys.resize( l_size + 1 );
333  m_polys[l_size] = a_poly;
334  m_sizes[l_size] = 1;
335  return l_size;
336  }
337 };
338 
339 
340 
341 //------------------------------------------------------------------------------
343 {
344 
345 private:
346  skTTerritory * Territories[400000]; // up to 400000 possible territories
348  int SimW, SimH;
349  bool* Grid;
350 
351  // This one is inlined for speed, belongs to EvaluateHabitat1().
352  // Many of the methods below are now inlined. FN, 2003-11-04.
353  int EvaluateHabitatSquare( int xmin, int xmax, int ymin, int ymax, int NoPolygons );
354 
355  int m_sim_w_div_10, m_sim_h_div_10;
358 
359  // The size of the next arrays.
361  int * m_poly_seen;
362  int * m_poly_size;
363  // m_qual_cache is quality per unit area for each polygon.
364  // Updated daily, but only if needed.
365  double * m_qual_cache;
367 
368  int m_for_iter_x[1000];
369  int m_for_iter_y[1000];
370  int PreMakeForIterator( int a_min_incl, int a_max_excl, int * a_iter, int a_norm_max_excl );
371  void PreFillTerrPolyLists( skTTerritory * a_terr );
372  void PreFillQualGrid( void );
373  void PreEvaluateQualGrid( SkQualGrid * a_grid, int a_x, int a_y, int a_width, int a_height );
374  void PreFillQualCache( void );
375 
376  // PrePoly2Qual() is where the actual evaluation of each polygon
377  // takes place.
378  //double PrePoly2Qual( int a_poly, int * a_good_polys );
379 
380  // Coordinates are in grid squares, ie. map coordinates divided by 10.
381  int PreEvaluateHabitat( int a_x, int a_y, int a_range_x, int a_range_y );
382  int PreEvaluateHabitatStripX( int a_x, int a_y, int a_range_x );
383  int PreEvaluateHabitatStripY( int a_x, int a_y, int a_range_x );
384 
385  void DumpMapGraphics( const char * a_filename, Landscape * a_map );
386 
387 public:
388  // New daily update method. Called by DoFirst() in the
389  // population manager.
390  void Tick( void )
391  {
392  m_qual_cache_filled = false;
393  }
394  void EvaluateAllTerritories( void );
395  void PreCachePoly(int a_poly);
396  double PrePoly2Qual( int a_poly );
397  double PrePolyNQual( int a_poly, int * a_good_polys );
398  int PolyRefData[2500];
399  int PolySizeData[2500];
400  double PolyHeightData[2500];
401  TTypesOfLandscapeElement PolyTypeData[2500];
403  void PreProcessLandscape2( Landscape * L );
404  void ClaimGrid( int x, int y, int range );
406  bool IsGridPositionValid( int & x, int & y, int range );
407  bool IsExtGridPositionValid( int & x, int & y, int range );
408  int IsValid( int nx, int ny );
409  void GetTerritoriesByDistance( int nx, int ny, vector<APoint> *alist );
410  int Supply_quality( int ref );
411  int Supply_x( int ref );
412  int Supply_y( int ref );
413  int Supply_size( int ref );
414  skTTerritory * Supply_terr( int ref );
415  void RemoveFemale( int ref );
416  void RemoveMale( int ref );
417  void Split( int ref );
418  Skylark_Male * Supply_Owner( int ref );
419  Skylark_Female * Supply_F_Owner( int ref );
420  void Occupy( int ref, Skylark_Male * Male );
421  void FemaleOccupy( int ref, Skylark_Female * Female );
422  double EvaluateHabitatN( skTTerritory * a_terr );
423  int SupplyNoTerritories();
424  int SupplyNoMaleOccupied();
425  int SupplyNoFemaleOccupied();
426  bool SupplyIsNestValid(int ref) {
427  return Territories[ref]->m_nest_valid;
428  }
430  APoint p(Territories[ref]->m_nest_pos_validx, Territories[ref]->m_nest_pos_validy);
431  return p;
432  }
433  SkTerritories( Landscape * L );
434  ~SkTerritories();
435 };
436 
437 
438 
439 //------------------------------------------------------------------------------
445 
446 
447 
448 //------------------------------------------------------------------------------
449 
451 {
452 protected:
453  #ifdef __CJTDebug_10
454  long refnum;
455  #endif
456  virtual void DoFirst();
457  void ProbeReportPOM( int a_time );
458  float ProbePOM( int ListIndex, probe_data * p_TheProbe );
461  double EMi; // EM in insect dry weight
462  void LoadParameters();
463  int m_StriglingMort[4];
471  // SK POM Files
472  FILE* SKPOM1;
473  FILE* SKPOM2;
474 
475 public:
476  void CreateObjects( int ob_type, TAnimal * pTAo, void * null, Skylark_struct * data, int number );
477  virtual void Init( void );
478 
479  void WriteSKPOM1( int n, int n2 ) {
480  fprintf( SKPOM1, "%i\t%i\n", n, n2 );
481  }
482  void WriteSKPOM2( int n, int n2 ) {
483  fprintf( SKPOM2, "%i\t%i\n", n, n2 );
484  }
485 
487  {
488  return M_Mig_Mort;
489  }
490 
492  {
493  return F_Mig_Mort;
494  }
495 
496  int SupplyNoTerritories();
497  int TheSkylarkTerrsSupply_x( int );
498  int TheSkylarkTerrsSupply_y( int );
499  int TheSkylarkTerrsSupply_size( int );
500  int TheSkylarkTerrsSupply_quality( int );
501 
502  void SetM_Mig_Mort( int m )
503  {
504  M_Mig_Mort = m;
505  }
506 
507  void SetF_Mig_Mort( int m )
508  {
509  F_Mig_Mort = m;
510  }
512 
513  virtual ~Skylark_Population_Manager( void );
514  // Special interfact functions for outputs
515  int TheFledgelingProbe();
516  virtual void BreedingPairsOutput( int Time );
517  void FledgelingProbeOutput( int Total, int Time );
518  int TheBreedingFemalesProbe( int ProbeNo );
519  bool OpenTheBreedingPairsProbe();
520  bool OpenTheFledgelingProbe();
521 
523  {
524  m_NoFledgeDeaths++;
525  }
526 
528  {
529  m_NoChickDeaths++;
530  }
531 
533  {
534  m_NoPestEffects++;
535  }
536 
537  void incTotalEggs(int eggs)
538  {
539  m_TotalEggs+=eggs;
540  }
541 
543  {
544  m_TotalNestlings++;
545  }
546 
548  {
549  m_TotalPrefledgelings++;
550  }
551 
552  void AddStriglingMort( int lifestage )
553  {
554  m_StriglingMort[lifestage] ++;
555  }
556 
557 
558  double SupplyEMi()
559  {
560  return EMi;
561  }
562 
563  bool IsBadWeather() {
564  return m_IsBadWeather;
565  }
566 
568  int VegTypeFledgelings[100];
569  virtual bool OpenTheBreedingSuccessProbe();
570  virtual void BreedingSuccessProbeOutput( double, int, int, int, int, int, int, int );
571  virtual int TheBreedingSuccessProbe( int & BreedingFemales, int & YoungOfTheYear, int & TotalPop,
572  int & TotalFemales, int & TotalMales , int & BreedingAttempts );
573  virtual void TheAOROutputProbe();
574  virtual void TheRipleysOutputProbe(FILE* a_prb);
575 
576  protected:
577  virtual void Catastrophe();
578  virtual void ReHouse();
579 
580 };
581 
582 
583 
584 //------------------------------------------------------------------------------
585 
586 class Skylark_Base : public TAnimal
587 {
588 public:
589  #ifdef __CJTDebug_10
590  long m_Ref;
591  #endif
593  double m_pcide_conc;
595  int Age;
596  double m_Size;
597  int m_Born_x;
598  int m_Born_y;
600  int m_MyHome;
601  // Object References
604  Skylark_Base( int x, int y, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM, int bx, int by, int mh );
605  virtual void ReInit(int x, int y, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM, int bx, int by, int mh);
606  virtual double On_FoodSupply( double /* food */ )
607  {
608  return 0.0;
609  }
610 
611  void AddStriglingMort( int lifestage )
612  {
613  m_OurPopulationManager->AddStriglingMort( lifestage );
614 
615  }
616 
617  // Returns the state number
618  virtual int WhatState()
619  {
620  return m_CurrentSkState;
621  }
622 
623  bool InSquare( rectangle R );
624 protected:
625  bool DailyMortality( int mort );
626 #ifdef __PESTICIDE_RA
627  double m_pcide;
628 #endif
629  virtual void PesticideResponse() { return; }
630 };
631 
632 
633 
634 //------------------------------------------------------------------------------
635 
637 {
638 protected:
639  // Behaviours
640  int st_Developing();
641  int st_Hatching();
642  void st_Dying();
643  // Attributes
646  virtual bool OnFarmEvent( FarmToDo event );
647 public:
648  // Behaviours
649  virtual void BeginStep( void );
650  virtual void Step( void );
651  virtual void EndStep( void );
652  Skylark_Clutch( Skylark_Female * Mum, SkTerritories * Terrs, Landscape * L, int NoEggs, int x, int y, int mh, Skylark_Population_Manager * SPM );
653  virtual void ReInit(Skylark_Female * Mum, SkTerritories * Terrs, Landscape * L, int NoEggs, int x, int y, int mh, Skylark_Population_Manager * SPM);
654  void OnMumGone();
655 
656  void AddEgg()
657  {
658  Clutch_Size++;
659  }
660 
662  {
663  m_CurrentSkState = toss_Developing;
664  // Must tell the pop man how many eggs were made
665  m_OurPopulationManager->incTotalEggs(Clutch_Size);
666  }
667 
668  // Attributes
671 };
672 
673 
674 
675 //------------------------------------------------------------------------------
676 
678 {
679  //Attributes
680 protected:
681  bool Sex;
684  // double Growth;
686  double m_EM;
687  double m_GrNeed;
688  //Behaviours
689  virtual int st_Developing();
690  virtual void st_Maturing();
691  virtual void st_Dying();
692  virtual bool OnFarmEvent(FarmToDo event);
693  virtual void PesticideResponse(void);
694 public:
695  Skylark_Nestling(int x, int y, Skylark_Male * Daddy, Landscape * L, SkTerritories * Terrs, Skylark_Population_Manager * SPM,
696  int bx, int by, int mh);
697  virtual void ReInit(int x, int y, Skylark_Male * Daddy, Landscape * L, SkTerritories * Terrs, Skylark_Population_Manager * SPM, int bx, int by, int mh);
698  virtual void BeginStep(void);
699  virtual void Step(void);
700  virtual void EndStep(void);
701  //Interface
702  virtual double On_FoodSupply(double food);
703  void OnDadDead();
704  void OnYouHaveBeenEaten();
705  void OnDeserted();
706 };
707 //------------------------------------------------------------------------------
708 
710 {
711 protected:
712  virtual int st_Developing();
713  virtual void st_Maturing();
714  virtual void st_Dying();
715  double GetFood();
716  double GetFledgelingEM(int Age);
717  virtual bool OnFarmEvent(FarmToDo event);
718  virtual void PesticideResponse();
719 public:
720  Skylark_PreFledgeling(int x, int y, Landscape * L, SkTerritories * Terrs, Skylark_Male * Daddy, bool sex, double size,
721  int age, Skylark_Population_Manager * SPM, int bx, int by, int mh);
722  virtual void ReInit(int x, int y, Landscape * L, SkTerritories * Terrs, Skylark_Male * Daddy, bool sex, double size,
723  int age, Skylark_Population_Manager * SPM, int bx, int by, int mh);
724  virtual void BeginStep(void);
725  virtual void Step(void);
726  virtual void EndStep(void);
727 };
728 //------------------------------------------------------------------------------
729 
731 {
732 protected:
733  // Methods
734  virtual double RemoveEM( double food );
735  double GetVegHindrance( int PolyRef );
736  double GetWeatherHindrance();
737  bool GetBadWeather();
738  // Attributes
740  bool BSuccess;
741  double MyExtractEff;
744  vector<APoint>* m_aTerrlist;
745 public:
746  Skylark_Adult(int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM,
747  int bx, int by, int mh);
748  virtual void ReInit(int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM,
749  int bx, int by, int mh);
750  virtual ~Skylark_Adult();
751  // Attributes
752  bool Paired;
753  virtual void CopyMyself(int a_sktype);
754 };
755 
756 
757 
758 //------------------------------------------------------------------------------
759 
761 {
762 protected:
763  int st_Flocking();
764  int st_Floating();
765  bool st_Arriving();
766  bool st_Immigrating();
767  int st_Emigrating();
768  int st_TempLeavingArea();
769  int st_Finding_Territory();
770  void st_Dying();
771  int st_CaringForYoung();
772  int st_BuildingUpResources();
773  TTypesOfSkState st_MakingNest();
774  int st_PreparingForBreeding();
775  int st_GivingUpTerritory();
776  TTypesOfSkState st_Laying();
777  int st_StartingNewBrood();
778  int st_EggHatching();
779  int st_Incubating();
780  int st_StoppingBreeding();
781  double GetFood( int time );
782  int CalculateEggNumber();
783  int CalcFoodTime( double target );
784  int GetMigrationMortality();
785  double CheckForFields();
786  void FeedYoung();
787  virtual bool OnFarmEvent( FarmToDo event );
788  virtual void PesticideResponse();
789  //bool TestNestPos( int x, int y );
790  skSpiralResult Spiral( int x, int y, int radius );
791  skSpiralResult Spiral2( int x, int y, int radius );
792  // Attributes
796  bool NestLoc;
797  double Resources;
803  int m_toowet;
805 public:
807  // Methods
808  Skylark_Female(int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM,
809  int bx, int by, int mh);
810  virtual void ReInit(int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM,
811  int bx, int by, int mh);
812  virtual void BeginStep(void);
813  virtual void Step( void );
814  virtual void EndStep( void );
815  void EstablishTerritory();
816 
817  //Interface
819  {
820  return m_NestTime;
821  }
822 
824  {
825  return MyClutch;
826  }
827 
828  int Supply_BreedingAttempts();
829  int Supply_BreedingSuccess();
830  void ResetBreedingSuccess();
831 
833  {
834  MyClutch = p_C;
835  }
836 
837  void OnEggsHatch();
838  void OnClutchDeath();
839  void OnBroodDeath();
840  void OnBreedingSuccess();
841  void OnStopFeedingChicks();
842  void OnMateDying();
843  void OnMateHomeless();
844  void OnMaleNeverComesBack( Skylark_Male * AMale );
845  void OnBreedSuccess() { m_BreedingSuccess++; }
846  void SensibleCopy();
847 
848 };
849 
850 
851 
852 //------------------------------------------------------------------------------
853 
855 {
856 
857 protected:
858  // Attributes
859  // Functions
860  int st_Flocking();
861  TTypesOfSkState st_Floating();
862  bool st_Arriving();
863  bool st_Immigrating();
864  int st_Emigrating();
865  int st_TempLeavingArea();
866  int st_FindingTerritory();
867  int st_AttractingAMate();
868  int st_FollowingMate();
869  void ConstructAHabitatTable();
870  int EstablishingATerritory();
871  int st_ScaringOffChicks();
872  int st_CaringForYoung();
873  void st_Dying();
875  void ReEvaluateTerritory();
876  double GetFood( int time );
877  void OptimiseHabitatSearchingOrder();
878  int GetMigrationMortality();
879  virtual bool OnFarmEvent( FarmToDo event );
880  virtual void PesticideResponse();
881  // Attributes
883  bool m_firstPF;
886  Skylark_Nestling * m_Brood[26]; //NB Nestling = base class for PreFledgling
889 public:
890  //for debugging
892  // to here
893  int BroodAge;
894 
895 public:
896  // Attributes
897  // Male's list of his habitats and their sizes & food availability
898  // **CJT** could be more efficient to move these three to the territory
899  vector <int>m_HabitatTable_PNum;
900  vector <int>m_HabitatTable_Size;
901  vector<double> m_InsectTable;
902 #ifdef __PESTICIDE_RA
903  vector<double>m_PConcTable;
904 #endif
905  //
907  // Methods
908  Skylark_Male( int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM,
909  int bx, int by, int mh );
910  virtual ~Skylark_Male();
911  virtual void ReInit(int x, int y, double size, int age, SkTerritories * Terrs, Landscape * L, Skylark_Population_Manager * SPM, int bx, int by, int mh);
912  virtual void BeginStep( void );
913  virtual void Step( void );
914  virtual void EndStep( void );
915  // Interface functions
916  #ifdef __CJTDebug_5
917  bool DoIExistN( Skylark_Nestling * N );
918  bool DoIExistP( Skylark_PreFledgeling * N );
919  #endif
920  bool OnEvicted();
921 
923  {
924  return No_HabitatTable_Refs;
925  }
926 
928  {
929  return m_BroodSize;
930  }
931 
932  int SupplyBroodAge( int n )
933  {
934  return m_Brood[n]->Age;
935  }
936 
939  return MyTerritory.nqual;
940  }
941 
942  int SupplyBroodWeight( int n )
943  {
944  return ( int )m_Brood[n]->m_Size;
945  }
946 
947 #ifndef __PESTICIDE_RA_CHICK
948  double OnFoodMessage( int n, double f )
949  {
950  double extra = m_Brood[n]->On_FoodSupply( f );
951  return extra;
952  }
953 #else
954  double OnFoodMessage( int n, double f , double p )
955  {
956  double extra = m_Brood[n]->On_FoodSupply( f );
957  m_Brood[n]->m_pesticide_accumulation+= (((f-extra)/f)*p);
958  return extra;
959  }
960 #endif
961 
962  void OnAddNestling( Skylark_Nestling * N );
963  void OnAddPreFledgeling( Skylark_PreFledgeling * P, Skylark_Nestling * N );
964  skTerritory_struct Supply_Territory();
965  int DefendTerritory();
966  void OnEggHatch();
967  void OnMateDying();
968  void OnMateLeaving();
969  void OnPairing( Skylark_Female * female );
970  void OnBroodDeath();
971  void OnNestLocation( int x, int y );
972  void OnNestlingDeath( Skylark_Nestling * N );
973  void OnPreFledgelingDeath( Skylark_PreFledgeling * P );
974  void OnPreFledgelingMature( Skylark_PreFledgeling * P );
975  void OnMateNeverComesBack( Skylark_Female * AFemale );
976  void OnNestPredatation();
977  void OnBroodDesertion();
978  void OnReHouse();
979  void SensibleCopy();
981  return m_OurPopulationManager->TheSkylarkTerrs->SupplyIsNestValid( MyTerritory.ref);
982  }
984  return m_OurPopulationManager->TheSkylarkTerrs->SupplyNestPosition( MyTerritory.ref );
985  }
986 };
987 //------------------------------------------------------------------------------
988 #endif
A simple class defining an x,y coordinate set.
Definition: ALMaSS_Setup.h:53
Definition: skylarks_all.h:251
double size
Definition: skylarks_all.h:253
bool sex
Definition: skylarks_all.h:254
int age
Definition: skylarks_all.h:255
A class defining an animals position.
Definition: PopulationManager.h:170
unsigned m_x
Definition: PopulationManager.h:172
unsigned m_y
Definition: PopulationManager.h:173
TTypesOfLandscapeElement m_EleType
Definition: PopulationManager.h:174
TTypesOfVegetation m_VegType
Definition: PopulationManager.h:175
The base class for all farm types.
Definition: farm.h:768
The landscape class containing all environmental and topographical data.
Definition: landscape.h:113
Definition: skylarks_all.h:228
Skylark_Male * Dad
Definition: skylarks_all.h:230
Base class for all population managers.
Definition: PopulationManager.h:424
Definition: skylarks_all.h:238
int age
Definition: skylarks_all.h:243
bool sex
Definition: skylarks_all.h:242
double size
Definition: skylarks_all.h:240
Skylark_Male * Dad
Definition: skylarks_all.h:241
Definition: skylarks_all.h:322
vector< int > m_polys
Definition: skylarks_all.h:325
double m_qual
Definition: skylarks_all.h:326
vector< int > m_sizes
Definition: skylarks_all.h:324
int Insert(int a_poly)
Definition: skylarks_all.h:328
Definition: skylarks_all.h:343
bool SupplyIsNestValid(int ref)
Definition: skylarks_all.h:426
int SimH
Definition: skylarks_all.h:348
double * m_qual_cache
Definition: skylarks_all.h:365
int * m_poly_size
Definition: skylarks_all.h:362
SkQualGrid ** m_qual_grid
Definition: skylarks_all.h:357
void UpdateQuality()
int * m_poly_seen
Definition: skylarks_all.h:361
bool m_qual_cache_filled
Definition: skylarks_all.h:366
int m_hash_size
Definition: skylarks_all.h:360
int NoTerritories
Definition: skylarks_all.h:347
void Tick(void)
Definition: skylarks_all.h:390
int m_sim_h_div_10
Definition: skylarks_all.h:355
bool * Grid
Definition: skylarks_all.h:349
Landscape * TheLandscape
Definition: skylarks_all.h:402
APoint SupplyNestPosition(int ref)
Definition: skylarks_all.h:429
int m_qual_grid_signal
Definition: skylarks_all.h:356
int EvaluateHabitatSquare(int xmin, int xmax, int ymin, int ymax, int NoPolygons)
Definition: skylarks_all.h:731
double MyExtractEff
Definition: skylarks_all.h:741
bool Paired
Definition: skylarks_all.h:752
int GoodWeather
Definition: skylarks_all.h:739
bool BSuccess
Definition: skylarks_all.h:740
skTerritory_struct MyTerritory
Definition: skylarks_all.h:743
int m_pesticide_affected
Definition: skylarks_all.h:742
vector< APoint > * m_aTerrlist
Definition: skylarks_all.h:744
Definition: skylarks_all.h:587
double m_pcide_conc
Definition: skylarks_all.h:593
Skylark_Population_Manager * m_OurPopulationManager
Definition: skylarks_all.h:603
virtual double On_FoodSupply(double)
Definition: skylarks_all.h:606
int m_MyHome
The vegetation type where the skylark was born.
Definition: skylarks_all.h:600
virtual int WhatState()
Definition: skylarks_all.h:618
int m_Born_y
Definition: skylarks_all.h:598
double m_Size
Definition: skylarks_all.h:596
int Age
Definition: skylarks_all.h:595
void AddStriglingMort(int lifestage)
Definition: skylarks_all.h:611
virtual void PesticideResponse()
Definition: skylarks_all.h:629
SkTerritories * m_OurTerritories
Definition: skylarks_all.h:602
TTypesOfSkState m_CurrentSkState
Definition: skylarks_all.h:594
int m_Born_x
Definition: skylarks_all.h:597
double m_pesticide_accumulation
Definition: skylarks_all.h:592
Definition: skylarks_all.h:637
void StartDeveloping()
Definition: skylarks_all.h:661
int m_baddays
Definition: skylarks_all.h:645
int MinDegrees
Definition: skylarks_all.h:644
int Clutch_Size
Definition: skylarks_all.h:669
void AddEgg()
Definition: skylarks_all.h:656
Skylark_Female * Mother
Definition: skylarks_all.h:670
Definition: skylarks_all.h:761
int m_EggNumber
Definition: skylarks_all.h:801
int m_Counter1
Definition: skylarks_all.h:794
void OnSetMyClutch(Skylark_Clutch *p_C)
Definition: skylarks_all.h:832
Skylark_Clutch * SupplyMyClutch()
Definition: skylarks_all.h:823
double m_MinFemaleAcceptScore
Definition: skylarks_all.h:804
skSpiralResult Spiral2(int x, int y, int radius)
bool NestLoc
Definition: skylarks_all.h:796
int Supply_NestTime()
Definition: skylarks_all.h:818
int m_toowet
Definition: skylarks_all.h:803
double Resources
Definition: skylarks_all.h:797
Skylark_Clutch * MyClutch
Definition: skylarks_all.h:793
int EggCounter
Definition: skylarks_all.h:798
int m_BreedingAttempts
Definition: skylarks_all.h:799
skSpiralResult Spiral(int x, int y, int radius)
int m_BreedingSuccess
Definition: skylarks_all.h:800
Skylark_Male * MyMate
Definition: skylarks_all.h:806
bool m_pesticide_sprayed_die
Definition: skylarks_all.h:802
int m_NestTime
Definition: skylarks_all.h:795
void OnBreedSuccess()
Definition: skylarks_all.h:845
Definition: skylarks_all.h:855
vector< int > m_HabitatTable_Size
Definition: skylarks_all.h:900
int m_MyMinTerritoryQual
Definition: skylarks_all.h:888
double OnFoodMessage(int n, double f)
Definition: skylarks_all.h:948
double m_XFNestAcceptScore
Definition: skylarks_all.h:882
double Supply_TerritoryQual()
Definition: skylarks_all.h:938
bool SupplyNestValid()
Definition: skylarks_all.h:980
vector< int > m_HabitatTable_PNum
Definition: skylarks_all.h:899
int m_BroodSize
Definition: skylarks_all.h:885
int SupplyBroodWeight(int n)
Definition: skylarks_all.h:942
bool HaveTerritory
Definition: skylarks_all.h:906
int BroodAge
Definition: skylarks_all.h:893
APoint SupplyNestLoc()
Definition: skylarks_all.h:983
int SupplyBroodSize()
Definition: skylarks_all.h:927
int GoodWeather
Definition: skylarks_all.h:884
vector< double > m_InsectTable
Definition: skylarks_all.h:901
Skylark_Female * MyMate
Definition: skylarks_all.h:891
bool m_firstPF
Definition: skylarks_all.h:883
int SupplyNoHabitatRefs()
Definition: skylarks_all.h:922
int No_HabitatTable_Refs
Definition: skylarks_all.h:887
int SupplyBroodAge(int n)
Definition: skylarks_all.h:932
Definition: skylarks_all.h:678
int m_EM_fail
Definition: skylarks_all.h:682
virtual double On_FoodSupply(double food)
Definition: skylarks_all.cpp:3312
int m_NestLeavingChance
Definition: skylarks_all.h:683
bool Sex
Definition: skylarks_all.h:681
double m_EM
Definition: skylarks_all.h:686
Skylark_Male * m_Dad
Definition: skylarks_all.h:685
double m_GrNeed
Definition: skylarks_all.h:687
Definition: skylarks_all.h:451
int M_Mig_Mort
Definition: skylarks_all.h:459
void SetM_Mig_Mort(int m)
Definition: skylarks_all.h:502
int F_Mig_Mort
Definition: skylarks_all.h:460
double EMi
Definition: skylarks_all.h:461
bool IsBadWeather()
Definition: skylarks_all.h:563
int m_TotalNestlings
Definition: skylarks_all.h:465
SkTerritories * TheSkylarkTerrs
Definition: skylarks_all.h:567
void incTotalPrefledgelings()
Definition: skylarks_all.h:547
int SupplyM_Mig_Mort()
Definition: skylarks_all.h:486
void incTotalEggs(int eggs)
Definition: skylarks_all.h:537
void incNoPestEffects()
Definition: skylarks_all.h:532
double SupplyEMi()
Definition: skylarks_all.h:558
int m_NoFledgeDeaths
Definition: skylarks_all.h:467
int m_NoPestEffects
Definition: skylarks_all.h:469
int m_TotalPrefledgelings
Definition: skylarks_all.h:466
void incNoFledgeDeaths()
Definition: skylarks_all.h:522
void WriteSKPOM2(int n, int n2)
Definition: skylarks_all.h:482
bool m_IsBadWeather
Definition: skylarks_all.h:470
FILE * SKPOM1
Definition: skylarks_all.h:472
void incTotalNestlings()
Definition: skylarks_all.h:542
int m_TotalEggs
Definition: skylarks_all.h:464
void WriteSKPOM1(int n, int n2)
Definition: skylarks_all.h:479
int m_NoChickDeaths
Definition: skylarks_all.h:468
int SupplyF_Mig_Mort()
Definition: skylarks_all.h:491
void incNoChickDeaths()
Definition: skylarks_all.h:527
void AddStriglingMort(int lifestage)
Definition: skylarks_all.h:552
FILE * SKPOM2
Definition: skylarks_all.h:473
void SetF_Mig_Mort(int m)
Definition: skylarks_all.h:507
Definition: skylarks_all.h:710
Definition: skylarks_all.h:196
int bx
Definition: skylarks_all.h:200
Landscape * L
Definition: skylarks_all.h:203
int x
Definition: skylarks_all.h:198
SkTerritories * Terrs
Definition: skylarks_all.h:204
int y
Definition: skylarks_all.h:199
int mh
Definition: skylarks_all.h:202
int by
Definition: skylarks_all.h:201
virtual ~Skylark_struct()
Definition: skylarks_all.h:206
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:205
Definition: skylarks_all.h:86
double Probe(probe_data *p_TheProbe)
Definition: skylarks_all.h:93
TSkylarkList()
Definition: skylarks_all.h:88
Data structure to hold & output probe data probe data is designed to be used to return the number of ...
Definition: PopulationManager.h:284
unsigned m_NoAreas
Definition: PopulationManager.h:292
TTypesOfVegetation m_RefVeg[25]
Definition: PopulationManager.h:297
rectangle m_Rect[10]
Definition: PopulationManager.h:293
unsigned m_RefFarms[25]
Definition: PopulationManager.h:299
unsigned m_NoFarms
Definition: PopulationManager.h:296
TTypesOfLandscapeElement m_RefEle[25]
Definition: PopulationManager.h:298
unsigned m_NoVegTypes
Definition: PopulationManager.h:295
unsigned m_NoEleTypes
Definition: PopulationManager.h:294
Definition: skylarks_all.h:217
Skylark_Female * Mum
Definition: skylarks_all.h:220
int No
Definition: skylarks_all.h:219
Definition: skylarks_all.h:184
int x
Definition: skylarks_all.h:186
int y
Definition: skylarks_all.h:187
bool found
Definition: skylarks_all.h:188
Definition: skylarks_all.h:263
double m_VirtualDiameter
Definition: skylarks_all.h:297
int m_Location_y
Definition: skylarks_all.h:283
int m_nest_pos_validy
Definition: skylarks_all.h:275
int m_y_div10
Definition: skylarks_all.h:271
Skylark_Female * F_Owner
Definition: skylarks_all.h:287
bool m_nest_valid
Definition: skylarks_all.h:273
double GetVirtualDiameter()
Definition: skylarks_all.h:277
vector< int > m_polys
Definition: skylarks_all.h:265
int m_nest_pos_validx
Definition: skylarks_all.h:274
double m_competitionscaler
Definition: skylarks_all.h:276
int m_x_div10
Definition: skylarks_all.h:270
vector< int > m_hr_polys
Definition: skylarks_all.h:267
int m_range_div10
Definition: skylarks_all.h:272
vector< int > m_hr_sizes
Definition: skylarks_all.h:268
double m_heterogeneity
Definition: skylarks_all.h:298
void SetQuality(int a_qual)
Definition: skylarks_all.h:285
vector< int > m_sizes
Definition: skylarks_all.h:266
int m_Quality
Definition: skylarks_all.h:299
Skylark_Male * Owner
Definition: skylarks_all.h:286
int m_Location_x
Definition: skylarks_all.h:282
void SetVirtualDiameter(double dia)
Definition: skylarks_all.h:278
void SetNestPossibility(bool valid, int nx, int ny)
Definition: skylarks_all.h:291
int Size
Definition: skylarks_all.h:281
int GetQuality(void)
Definition: skylarks_all.h:284
Definition: skylarks_all.h:306
int x
Definition: skylarks_all.h:308
int size
Definition: skylarks_all.h:310
bool validnest
Definition: skylarks_all.h:313
int ref
Definition: skylarks_all.h:311
double nqual
Definition: skylarks_all.h:312
int y
Definition: skylarks_all.h:309
SkylarkObject
Definition: skylarks_all.h:35
@ sob_Clutch
Definition: skylarks_all.h:36
@ sob_Male
Definition: skylarks_all.h:39
@ sob_Nestling
Definition: skylarks_all.h:37
@ sob_Female
Definition: skylarks_all.h:40
@ sob_PreFledgeling
Definition: skylarks_all.h:38
TTypesOfSkState
Definition: skylarks_all.h:44
@ toss_StartingNewBrood
Definition: skylarks_all.h:59
@ toss_Initiation
Definition: skylarks_all.h:45
@ toss_BuildingUpResources
Definition: skylarks_all.h:58
@ toss_MakingNest
Definition: skylarks_all.h:58
@ toss_FEmigrating
Definition: skylarks_all.h:57
@ toss_MCaringForYoung
Definition: skylarks_all.h:55
@ toss_FDying
Definition: skylarks_all.h:59
@ toss_MDying
Definition: skylarks_all.h:55
@ toss_MRehousing
Definition: skylarks_all.h:55
@ toss_StoppingBreeding
Definition: skylarks_all.h:59
@ toss_NDying
Definition: skylarks_all.h:49
@ toss_EggHatching
Definition: skylarks_all.h:59
@ toss_MFlocking
Definition: skylarks_all.h:53
@ toss_FCaringForYoung
Definition: skylarks_all.h:59
@ toss_Developing
Definition: skylarks_all.h:47
@ toss_FImmigrating
Definition: skylarks_all.h:57
@ toss_FTempLeavingArea
Definition: skylarks_all.h:57
@ toss_MEmigrating
Definition: skylarks_all.h:53
@ toss_Destroy
Definition: skylarks_all.h:62
@ toss_MFloating
Definition: skylarks_all.h:53
@ toss_MImmigrating
Definition: skylarks_all.h:53
@ toss_PreparingForBreeding
Definition: skylarks_all.h:58
@ toss_MArriving
Definition: skylarks_all.h:53
@ toss_FFindingTerritory
Definition: skylarks_all.h:58
@ toss_NMaturing
Definition: skylarks_all.h:49
@ toss_PDying
Definition: skylarks_all.h:51
@ toss_AttractingAMate
Definition: skylarks_all.h:54
@ toss_FollowingMate
Definition: skylarks_all.h:54
@ toss_ScaringOffChicks
Definition: skylarks_all.h:54
@ toss_CDying
Definition: skylarks_all.h:47
@ toss_PDeveloping
Definition: skylarks_all.h:51
@ toss_NDeveloping
Definition: skylarks_all.h:49
@ toss_Incubating
Definition: skylarks_all.h:59
@ toss_Hatching
Definition: skylarks_all.h:47
@ toss_FFlocking
Definition: skylarks_all.h:57
@ toss_Laying
Definition: skylarks_all.h:58
@ toss_PMaturing
Definition: skylarks_all.h:51
@ toss_MTempLeavingArea
Definition: skylarks_all.h:53
@ toss_FArriving
Definition: skylarks_all.h:57
@ toss_GivingUpTerritory
Definition: skylarks_all.h:60
@ toss_MFindingTerritory
Definition: skylarks_all.h:54
@ toss_FFloating
Definition: skylarks_all.h:57
TSkylarkList< Skylark_Clutch * > Skylark_ClutchList
Definition: skylarks_all.h:440
TSkylarkList< Skylark_Nestling * > Skylark_NestlingList
Definition: skylarks_all.h:441
TSkylarkList< Skylark_Male * > Skylark_MaleList
Definition: skylarks_all.h:443
TSkylarkList< Skylark_Female * > Skylark_FemaleList
Definition: skylarks_all.h:444
TSkylarkList< Skylark_PreFledgeling * > Skylark_PreFledgelingList
Definition: skylarks_all.h:442
A struct defining two x,y coordinate sets of positive co-ords only.
Definition: PopulationManager.h:98
unsigned m_x1
Definition: PopulationManager.h:100
unsigned m_x2
Definition: PopulationManager.h:102
unsigned m_y2
Definition: PopulationManager.h:103
unsigned m_y1
Definition: PopulationManager.h:101
TTypesOfLandscapeElement
Definition: tole_declaration.h:36
FarmToDo
Definition: treatment.h:31